#coding=utf-8
class colorformat:
    format = {
            "0" : "black",
            "1" : "dark_blue",
            "2" : "dark_green",
            "3" : "dark_aqua",
            "4" : "dark_red",
            "5" : "dark_purple",
            "6" : "gold",
            "7" : "gray",
            "8" : "dark_gray",
            "9" : "blue",
            "a" : "green",
            "b" : "aqua",
            "c" : "red",
            "d" : "light_purple",
            "e" : "yellow",
            "f" : "white",
            "r" : "default",
            "k" : "random",
            "l" : "strong",
            "m" : "delete",
            "n" : "underline",
            "o" : "italic"
    }
    keyword = "&"
    string = str()
    def __init__(self):
        pass

    def __handle__(self):
        istring = self.string.split(self.keyword)
        IReturn = list()
        for i in range(len(istring)):
            ITuple = tuple()
            if istring[i] != "":
                if istring[i][0] in self.format.keys():
                    value = self.format[istring[i][0]]
                    if len(istring[i]) - 1 != 0:
                        keys = istring[i][1:len(istring[i]) - 1]
                    else:
                        continue
                else:
                    keys = istring[i]
                    value = "default"
                ITuple = (keys, value)
                IReturn.append(ITuple)
        return IReturn

    def handle(self, string):
        pass
        self.string = string
        return self.__handle__(self)
        
    def deleteAll(self, string):
        pass
        self.string = string
        IData = self.__handle__(self)
        IReturn = str()
        for i in IData:
            IReturn += i[0]

        return IReturn